//
//  BaseModel.m
//  uteped_sdk
//
//  Created by mateng on 2024/2/28.
//

#import "BaseModel.h"

@implementation BaseModel

- (id)initWithAddress:(NSString *)address {
    if (self = [super init]) {
        self.storeData = [[NSMutableDictionary alloc] init];
        self.dateCreated = [[NSDate date] timeIntervalSince1970];
        self.dateModified = self.dateCreated;
        self.address = address;
        
        [self.storeData setObject:@(self.dateCreated) forKey:@"date_created"];
        [self.storeData setObject:@(self.dateModified) forKey:@"date_modified"];
        [self.storeData setObject:self.address forKey:@"address"];
    }
    
    return self;
}

- (NSString *)getKeyString {
    NSArray *allKeys = [self.storeData allKeys];
    NSMutableString *keyStr = [[NSMutableString alloc]init];
    for(NSString *key in allKeys)
        [keyStr appendFormat:@"'%@', ", key];
    [keyStr replaceOccurrencesOfString:@", " withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(keyStr.length - 2, 2)];
    
    return keyStr;
}

- (NSString *)getValueString {
    NSArray *allKeys = [self.storeData allKeys];
    NSMutableString *valueStr = [[NSMutableString alloc]init];
    for (NSString *key in allKeys) {
        [valueStr appendFormat:@"'%@', ", [self.storeData objectForKey:key]];
    }
    [valueStr replaceOccurrencesOfString:@", " withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(valueStr.length-2, 2)];
    
    return valueStr;
}

@end
